﻿using Admin2024.Api.Filter;
using Admin2024.Application.Contracts.Permission;
using Admin2024.Application.Contracts.Permission.Dto;
using Admin2024.Application.Permission.Dto;
using Admin2024.Domain.Entity.System;
using Admin2024.Domain.ObjValue;
using Microsoft.AspNetCore.Mvc;

namespace Admin2024.Api.Controller
{
    [ApiController]
    //[TypeFilter(typeof(CtmAuthorizationFilterAttribute))]
    public class AppPermissionController : ControllerBase
    {

        private readonly IPermissionService _permissionService;

        public AppPermissionController(IPermissionService permissionService)
        {
            _permissionService = permissionService;
        }
        /// <summary>
        /// 新增权限
        /// </summary>
        /// <param name="permissionCreateDto"></param>
        /// <returns></returns>
        [HttpPost("/api/AddPermission")]
        public async Task<DomainResult<PermissionCreateSucessDto>> AddPermission(PermissionCreateDto permissionCreateDto)
        {
            return await _permissionService.CreatePermission(permissionCreateDto);
        }

        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("/api/DeletePermission/{Id}")]
        public async Task<DomainResult<AppPermission>> DeletePermission(Guid Id)
        {
            return await _permissionService.DeletePermission(Id);
        }


        /// <summary>
        /// 新增操作权限
        /// </summary>
        /// <param name="operationCreateDto"></param>
        /// <returns></returns>
        [HttpPost("/api/AddOperation")]
        
        public async Task<DomainResult<OperationCreateSucessDto>> AddOperation(OperationCreateDto operationCreateDto)
        {
            return await _permissionService.CreateOperation(operationCreateDto);
        }
        /// <summary>
        /// 删除操作权限
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("/api/DeleteOperation/{Id}")]
        public async Task<DomainResult<AppOperation>> DeleteOperation(Guid Id)
        {
            return await _permissionService.DeleteOperation(Id);
        }

        /// <summary>
        /// 新增资源权限
        /// </summary>
        /// <param name="resourceCreateDto"></param>
        /// <returns></returns>
        [HttpPost("/api/AddResource")]
        public async Task<DomainResult<ResourceCreateSucessDto>> AddResource(ResourceCreateDto resourceCreateDto)
        {
            return await _permissionService.CreateResource(resourceCreateDto);
        }
        /// <summary>
        /// 删除资源权限
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("/api/DeleteResource/{Id}")]
        public async Task<DomainResult<AppResource>> DeleteResource(Guid Id)
        {
            return await _permissionService.DeleteResource(Id);
        }


        //获取所有权限
        [HttpGet("/api/GetAllPermission")]
        public async Task<DomainResult<List<PermissionDto>>> GetAllPermission(int page=1,int pageSize=10)
        {
            return await _permissionService.GetPermissionWithPagination(page, pageSize);
        }
        //获取指定权限
        [HttpGet("/api/GetByIdPermission/{id}")]
        public async Task<DomainResult<PermissionDto>> GetByIdPermission(Guid id)
        {
            return await _permissionService.GetAppPermissionById(id);
        }


        //获取指定操作权限
        [HttpGet("/api/GetByIdOperation/{id}")]
        public async Task<DomainResult<OperationDto>> GetByIdOperation(Guid id)
        {
            return await _permissionService.GetOperationById(id);
        }
        //获取所有操作权限
        [HttpGet("/api/GetAllOperation")]
        public async Task<DomainResult<List<OperationDto>>> GetAllOperation(int page = 1, int pageSize = 10)
        {
            return await _permissionService.GetOperationWithPagination(page, pageSize);
        }

        //修改操作权限
        [HttpPut("/api/UpdateOperation/{id}")]
        public async Task<DomainResult<OperationDto>> UpdateOperation(Guid id, OperationUpdateDto  operationUpdateDto)
        {
            return await _permissionService.UpdateOperationProfile(id, operationUpdateDto);
        }
        //获取指定资源权限
        [HttpGet("/api/GetByIdResource/{id}")]
        public async Task<DomainResult<ResourceDto>> GetByIdResource(Guid id)
        {
            return await _permissionService.GetAppResourceById(id);
        }
        //获取所有资源权限
        [HttpGet("/api/GetAllResource")]
        public async Task<DomainResult<List<ResourceDto>>> GetAllResource(int page = 1, int pageSize = 10)
        {
            return await _permissionService.GetResourceWithPagination(page, pageSize);
        
        }


        //修改资源权限
        [HttpPut("/api/UpdateResource/{id}")]
        public async Task<DomainResult<ResourceDto>> UpdateResource(Guid id, ResourceUpdateDto  resourceUpdateDto)
        {
            return await _permissionService.UpdateResourceProfile(id, resourceUpdateDto);
        }
    }
}
